package cn.bonoon.controllers.fmm;

import cn.bonoon.core.IRoleEditor;
import cn.bonoon.kernel.annotations.Transform;
import cn.bonoon.kernel.annotations.TransformField;
import cn.bonoon.kernel.annotations.WriteModel;
import cn.bonoon.kernel.support.models.ObjectEditor;
import cn.bonoon.kernel.web.EmbedType;
import cn.bonoon.kernel.web.annotations.components.AsCheckbox;
import cn.bonoon.kernel.web.annotations.components.AsComponent;
import cn.bonoon.kernel.web.annotations.components.AsSelector;
import cn.bonoon.kernel.web.annotations.components.AsTextArea;
import cn.bonoon.kernel.web.annotations.form.FormEditor;
import cn.bonoon.kernel.web.annotations.form.PropertyEditor;

@Transform
@FormEditor(2)
public class RoleEditor extends ObjectEditor implements IRoleEditor, RoleDefine {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1065192113270215238L;

	@PropertyEditor(value = 0, required = true)
	private String name;

	@PropertyEditor(name = "默认角色", value = 1)
	@AsCheckbox("是")
	private boolean defaultRole;

	@PropertyEditor(2)
	@AsSelector
	private int status;

	@PropertyEditor(value = 4, required = true, colspan = 1)
	private String roleKey;

	@PropertyEditor(3)
	@AsSelector(modelOptions = "moduleKey", 
		title = "", 
		onChange = "jQuery('#div-privileges').load(jQuery(this).val()+'!privileges.do?roleid='+id);")
	// onChange = "jQuery('#div-privileges').load(newValue+'!privileges.do?roleid='+id);"
	private String moduleKey;

	@PropertyEditor(value = 5, colspan = 1)
	@TransformField(readable = false, writable = WriteModel.NONE)
	@AsComponent(value = "sys/account/module-menu-editable.vm", type = EmbedType.PARSE)
	private String[] privileges;

	@PropertyEditor(value = 6, colspan = 1)
	@AsTextArea
	private String remark;

	public boolean isDefaultRole() {
		return defaultRole;
	}

	public void setDefaultRole(boolean defaultRole) {
		this.defaultRole = defaultRole;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String[] getPrivileges() {
		return privileges;
	}

	public void setPrivileges(String[] privileges) {
		this.privileges = privileges;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getRoleKey() {
		return roleKey;
	}

	public void setRoleKey(String roleKey) {
		this.roleKey = roleKey;
	}

	public String getModuleKey() {
		return moduleKey;
	}

	public void setModuleKey(String moduleKey) {
		this.moduleKey = moduleKey;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

}
